package com.weixin.common.sftp;

import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 实例化对象池和操作类
 *
 * @author zh
 * @date 2022/7/26 15:30
 */
@Configuration
@EnableConfigurationProperties({ClientProperties.class, PoolProperties.class})
public class SftpPoolConfig {

    @Bean
    public SftpPool sftpPool(ClientProperties clientProperties, PoolProperties poolProperties) {
        return clientProperties.getHosts() == null ?
                new SftpPool(clientProperties, poolProperties) :
                new SftpPool(HostHolder.initHostNames(clientProperties.getHosts()), poolProperties);
    }

    @Bean
    public SftpTemplate sftpTemplate(SftpPool sftpPool) {
        return new SftpTemplate(sftpPool);
    }
}
